<template>
    <div class="liulanyonghu">
          <el-table :data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)" border style="width: 900px">
            <el-table-column fixed prop="UID" label="ID" width="150"></el-table-column>
            <el-table-column prop="uname" label="昵称" width="120"></el-table-column>
            <el-table-column prop="zhenname" label="真实姓名" width="120"></el-table-column>
            <el-table-column prop="himg" label="头像" width="300"></el-table-column>
            <el-table-column prop="sex" label="性别" width="120"></el-table-column>
            <el-table-column prop="zhuangtai" label="状态" width="120"></el-table-column>
            <el-table-column fixed="right" label="操作" width="100">
              <template slot-scope="scope">
                <el-button @click="handleClick(scope.row)" type="text" size="small">删除</el-button>
                <el-button type="text" size="small" @click="bj(scope.row)">编辑</el-button>
              </template>
            </el-table-column>
          </el-table>
         <el-pagination :page-size="pagesize" @current-change="currentchange" :current-page.sync="currentPage" layout="prev, pager, next" :total="tableData.length"></el-pagination>
         <div class="bianjiyh" :class="{hyh:pl}">
           <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
  <el-form-item label="昵称" prop="name">
    <el-input v-model="ruleForm.name" style="width:300px"></el-input>
  </el-form-item>
  <el-form-item label="性别" prop="region">
    <el-select v-model="ruleForm.region" placeholder="请选择性别">
      <el-option label="男" value="1"></el-option>
      <el-option label="女" value="0"></el-option>
    </el-select>
  </el-form-item>
   <el-form-item label="头像" prop="img" ><el-button type="primary" @click="sad">默认</el-button>
    <el-input v-model="ruleForm.img" style="width:300px" :disabled="true"></el-input>
  </el-form-item>
  <el-form-item label="状态" prop="regios">
    <el-select v-model="ruleForm.resource" placeholder="请选择状态">
      <el-option label="冻结" value="1"></el-option>
      <el-option label="正常" value="0"></el-option>
    </el-select>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
    <!-- <el-button @click="resetForm('ruleForm')">重置</el-button> -->
  </el-form-item>
</el-form>
         </div>
        </div>
</template>
<script>
export default {
  methods: {
    handleClick(val){
      axios.post("/api/shanchuyonghu",{id:val.UID}).then((data)=>{
        if(data.data){
          this.pl=true
          this.tableData=data.data
        }else{
           this.$toast({
                    message:"删除失败",
                    duration:1500
                  })
                  return false
        }
      })
    },
    bj(val){
      this.pl=false
      console.log(val)
      this.ruleForm.name=val.uname
      this.ruleForm.region=val.sex
      this.ruleForm.img=val.himg
      this.ruleForm.resource=val.zhuangtai
      this.id=val.UID
    },
    sad(){
      this.ruleForm.img="./images/tx/mrtx.jpg"
    },
   currentchange(val){
            console.log(val)
            this.currentPage=val
        },
    submitForm(formName) {
       var _this=this
             var ab = function (params) {
              let flag = true;
              for(var key in params){
                if(params[key] != '0' && !params[key]){
                  console.log('请完善数据!');
                  _this.$toast({
                    message:"请完善数据",
                    duration:1500
                  })
                  return false; // 终止程序
                }
              }
            
              return flag;
            }
            ab(this.ruleForm)
        axios.post("/api/xiugaiyonghu",{rul:this.ruleForm,id:this.id}).then((data)=>{
          if(data.data){
            _this.$toast({
                    message:"修改成功",
                    duration:1500
                  })
                  this.pl=true
          }else{
            _this.$toast({
                    message:"修改失败请重新修改",
                    duration:1500
                  })
          }
        })
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
  },
  filters:{
    sexs(val){
      return val?'冻结':'正常'
    }
  },
  created(){
    axios.get("/api/dpyilan").then((data)=>{
      if(data.data){
        this.tableData=data.data
      }else{

      }
    })
  },
  data() {
    return {
      id:"",
      pl:true,
      ruleForm: {
          name: '',
          region: '',
          resource: "",
          img:""
        },
        rules: {
          name: [
            { required: true, message: '请输入昵称', trigger: 'blur' },
            { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          region: [
            { required: true, message: '请选择性别', trigger: 'change' }
          ],
          regions: [
            { required: true, message: '请选择状态', trigger: 'change' }
          ],
        },
      pagesize:5,
      currentPage:1,
      tableData: [],
     
    };
  }
};
</script>
<style>
.hyh{
  display: none;
}
 .el-pagination{
        text-align: center;
        margin: 10px 0 20px 0;
    }
</style>


